import Api from '@/api/system/users'
import levelsAPI from '@/api/client/levels.js'
import i18n from "@/lang/index";
const modalConfig = {
  pageName: "sys:user",
  dialog: {
    title: i18n.global.t("title.2"),
    width: 800,
    appendToBody: true,
    draggable: true,
    labelWidth: "auto",
  },
  formAction: (data) => {
    console.log("add", data);
    return new Promise((resolve, reject) => {
      Api.add(data).then(s => {
        console.log(s);
        resolve(s)
      }).catch(e => {
        reject(e)
      })
    });
  },
  formItems: [
    {
      type: "input",
      label: i18n.global.t("form.1"),
      prop: "username",
      attrs: {
        placeholder: i18n.global.t("hint.4"),
      },
    },
    {
      type: "input",
      label: i18n.global.t("form.68"),
      prop: "name",
      attrs: {
        placeholder: i18n.global.t("hint.132"),
      },
    },
    {
      type:"select",
      label: i18n.global.t("label.64"),
      prop: "vip_level_id",
      attrs: {
        placeholder: i18n.global.t("hint.104"),
      },
      options:[],
      initFn(){
        levelsAPI.getList().then((res) => {
          this.options = res.data.map((item) => {
            return {
              label: item.name,
              value: item.level,
            }
          })
        });
      },
    },
    {
      type: "input",
      label: i18n.global.t("form.6"),
      prop: "email",
      attrs: {
        placeholder: i18n.global.t("hint.3"),
      },
    },
    {
      type: "input",
      label: i18n.global.t("label.1"),
      prop: "phone_number",
      attrs: {
        placeholder: i18n.global.t("hint.79"),
      },
    },
    {
      type: "input",
      label: i18n.global.t("form.7"),
      prop: "password",
      attrs: {
        placeholder: i18n.global.t("hint.6"),
      }
    },
    {
      type: "input",
      label: i18n.global.t("form.70"),
      prop: "payment_password",
      attrs: {
        placeholder: i18n.global.t("hint.159"),
      }
    },
    {
      type: "radio",
      label: i18n.global.t("label.106"),
      prop: "is_test",
      options: [ 
        { label: i18n.global.t("status.1"), value: 1 },
        // { label: i18n.global.t("status.2"), value: 0 },
      ],
      initialValue: 1,
      // col: {
      //   span: 12,
      // }
    },

  ],
  formRules: {
    username: [{ required: true, message: i18n.global.t("hint.4"), trigger: "blur" }],
    name: [{ required: true, message: i18n.global.t("hint.132"), trigger: "blur" }],
    password: [{ required: true, message: i18n.global.t("hint.6"), trigger: "blur" }],
    vip_level_id: [{ required: true, message: i18n.global.t("hint.104"), trigger: "change" }]
  },
};

export default modalConfig;
